package com.aisile.crowd_funding01.system.service.impl;

import com.aisile.crowd_funding01.system.mapper.SysMenuMapper;
import com.aisile.crowd_funding01.system.pojo.SysMenu;
import com.aisile.crowd_funding01.system.pojo.SysMenuExample;
import com.aisile.crowd_funding01.system.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class MenuSericeImpl implements MenuService{
    @Autowired
    SysMenuMapper sysMenuMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return sysMenuMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(SysMenu record) {
        return sysMenuMapper.insert(record);
    }

    @Override
    public SysMenu selectByPrimaryKey(Long id) {
        return sysMenuMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKey(SysMenu sysMenu) {
        return sysMenuMapper.updateByPrimaryKey(sysMenu);
    }

    @Override
    public List<SysMenu> selectByExample(SysMenuExample sysMenuExample) {
        return sysMenuMapper.selectByExample(sysMenuExample);
    }

    @Override
    public int selectChildCount(Long parentId) {
        SysMenuExample sysMenuExamaple = new SysMenuExample();
        sysMenuExamaple.createCriteria().andParentIdEqualTo(parentId);
        List<SysMenu> sysMenus = sysMenuMapper.selectByExample(sysMenuExamaple);

        return sysMenus.size();
    }
}
